import { useEffect, useRef } from "react"
import * as echarts  from "echarts";
const BarChart = ({ title }) => {
  const mainRef = useRef(null)
  useEffect(() => {
   
    const myChart = echarts.init(mainRef.current);
    // 指定图表的配置项和数据
    const option = {
        title: {
            text: title
        },
        tooltip: {},
        legend: {
            data:['销量']
        },
        xAxis: {
            data: ["vue","react","arguline"]
        },
        yAxis: {},
        series: [{
            name: '销量',
            type: 'bar',
            data: [5, 20, 36]
        }]
    };

    // 使用刚指定的配置项和数据显示图表。
    option && myChart.setOption(option);
  }, [title])
  return (
    <div>
      <div ref={mainRef} style={{width: '500px', height:'400px' }}></div>
    </div>
  )
}

export default BarChart